from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QScrollArea, QFrame, QTableWidget, QTableWidgetItem
from config import frame_config
def clear_layout( layout):
    if layout is None:
        return
    # 从布局中移除所有项目
    while layout.count():
        item = layout.takeAt(0)
        widget = item.widget()
        if widget:  # 如果是控件则删除
            widget.deleteLater()
        else:  # 如果是子布局则递归清除
            clear_layout(item.layout())
            item.layout().deleteLater()
#创建一带有滑块的容器
def create_scroll(layout):
    scroll_area = QScrollArea()
    scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
    scroll_area.setWidgetResizable(True)
    frame = QFrame()
    frame.setStyleSheet(frame_config.frame_style4)
    scroll_area.setWidget(frame)
    layout.addWidget(scroll_area)
    return frame

#差入一个表格
def create_tabel(layout,labels,history_list):
    col = len(labels)
    row = len(history_list)
    tabel_history = QTableWidget()
    layout.addWidget(tabel_history)
    tabel_history.setRowCount(row)
    tabel_history.setColumnCount(col)
    tabel_history.setHorizontalHeaderLabels(labels)
    data = history_list
    for row in range(len(data)):
        for col in range(len(data[row])):
            item = QTableWidgetItem(str(data[row][col]))
            tabel_history.setItem(row, col, item)


